const express = require('express')
const app = express()
const mysql = require('mysql')
const db = mysql.createPool({
    host: 'localhost',
    port: 3306,
    user: 'root',
    password: '123456',
    database: 'shopdb'
})
//增加数据
app.get('/css', (reg, res) => {
    let sql = "insert into t_goods(title,content,imagePath,price) values('hshhja','sdsd','dsguys',2800)"
    db.query(sql, [], (err, result) => {
        res.send(result)
    })
})
//删除数据
app.get('/hhh', (req, res) => {
    let sql = 'delete from t_goods where id=?'
    db.query(sql, [3], (err, result) => {
        res.send(result)
    })
    //修改数据
    app.post('/hg', (req, res) => {
        let sql = "update t_goods set content is null where id=2"
        db.query(sql, [], (err, result) => {
            res.send(err)
        })
    })
    //查看数据
    app.get('/smwy', (req, res) => { 
        let sql = 'select * from t_goods where price>2000'
        db.query(sql, [], (err, result) => {
            res.send(result)
        })
    })
    
})
app.listen(3000, () => {
        
        console.log('server is running at port 3000')
    })